package com.yuyu.demo.spring4.beans;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainTest {
	
	private static final String Car = null;
	private static ApplicationContext applicationContext;
	
	public static void main(String[] args) {
		//初始化容器  ClassPathXmlApplicationContext FileSystemtXmlApplicationContext
		applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
		//根据id获取bean
		Car CarByName = (Car)applicationContext.getBean("myCar");
		//根据类型获取bean，如果bean类型有多个，则会报错
		//Car CarByType = (Car)applicationContext.getBean(Car.class);
		//使用bean
		System.out.println(CarByName.toString());
		
		Car myCar2 = (Car)applicationContext.getBean("myCar2");
		System.out.println(myCar2.toString());
	}
}
